/**
 *
 * 欢迎页 
 * 动画 TODO
 * 
 */
class SplashView extends BaseEuiView {
    public bgView: eui.Image;
    public logoView: eui.Image;
    public peopleView: eui.Image;
    public titleView: eui.Image;
    public scrollView : eui.Image;
    
    private mx:number;
    private my:number;
    
    private timeOnEnterFrame:number =0;
    
    
    private preLoop = 30;
    private suffixY = 80;
    private aniSuffixY = 12;
    private initBottom :number;
    private add:boolean = true;
    
    
    
    public constructor() {
        super();
    }
     
    protected initUI(): void {
        this.left = this.right = this.bottom = this.top = 0;
        this.bgView.alpha = 0;
        this.peopleView.alpha = 0;
        this.initBottom = this.scrollView.bottom;
        
        egret.Tween.get(this.bgView).wait(0).to({ alpha: 1 },600);
        egret.Tween.get(this.peopleView).wait(400).to({ alpha: 1 },300);
        
        this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchHandler , this);
        this.addEventListener(egret.Event.ENTER_FRAME,this.canvasLoop,this);
        this.timeOnEnterFrame = egret.getTimer();
    }
    
    
    private canvasLoop(evt: egret.Event ){
        var now = egret.getTimer();
        var time = this.timeOnEnterFrame;
        var pass = now - time;
        if(pass >= this.preLoop){
            var currentBottom = this.scrollView.bottom;
            if(currentBottom<= this.initBottom){
                this.add = true;
            } else if(currentBottom >= this.initBottom + this.aniSuffixY){
                this.add = false;
            }
            if(this.add){
                this.scrollView.bottom ++;
            }else{
                this.scrollView.bottom --;
            }
            this.timeOnEnterFrame = egret.getTimer();
        }
        
    }
    
    protected exml(): string {
        return "SplashSkin";
    }

    private touchHandler(evt: egret.TouchEvent ){
        switch(evt.type) {
            case egret.TouchEvent.TOUCH_BEGIN:
                this.mx = evt.stageX;                this.my = evt.stageY;
                this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchHandler,this);                this.addEventListener(egret.TouchEvent.TOUCH_END,this.touchHandler,this);
                break;
            case egret.TouchEvent.TOUCH_END:
                this.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchHandler,this);                this.removeEventListener(egret.TouchEvent.TOUCH_END,this.touchHandler,this);
                var yDiff = this.my - evt.stageY;
                if(yDiff > this.suffixY){
                    this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN , this.touchHandler , this);
                    this.dispatchEventWith(CMDEvent.SCROLL_SPLASH);
                }
                break;
            case egret.TouchEvent.TOUCH_MOVE:
                break;
        }
    }
    
}
